<?php
namespace Home\Controller;
use Think\Controller;
use Alipay\aop\AopClient;
use Alipay\aop\request\AlipayOpenPublicTemplateMessageIndustryModifyRequest;
use Alipay\aop\SignData;

class IndexController extends Controller {
	public function _initialize(){

		if(isMobile()){
			$this->redirect("Mobile/Index/index");
		}
		$lg=$_GET["lg"];
		if($lg=="logout"){
			session("loginname",null);
		}
		if($_SESSION["loginname"]){
			$headimg = D("user")->where("phone='%s' or mail='%s'",$_SESSION["loginname"],$_SESSION["loginname"])->getField("headimg");
			$this->assign("loginname",$_SESSION['loginname']);
			$this->assign("headimg",$headimg);
			$this->assign("logined",1);
		}else{
			$this->assign("logined",0);
		}
	}
	//首页
    public function index(){
    	$lunbolist = D("lunbo")->where("status=1")->select();
    	$adlist = D("ad")->where("status=1")->order('adorder desc')->select();
    	$homenotice = D("admin")->where("id=1")->getField("homenotice");
    	$this->assign('homenotice',$homenotice);
    	$this->assign('lunbolist',$lunbolist);
    	$this->assign('adlist',$adlist);
		$this->display(":index");
    }
	//登录页面
	public function weblogin(){
		$do = $_GET["do"];
		if($do=='login'){
			if(empty($_POST["username"])){
				$this->error("用户账号不许为空");
			}
			$dbpassword = D("user")->where("phone='%s' or mail='%s'",$_POST['username'],$_POST['username'])->getField('password');
			if(!$dbpassword){
				$this->error("用户不存在");
			}
			if($dbpassword==$_POST['userpassword']){
				$verify = I('param.verify','');
				if(!check_verify($verify)){
					$this->error("验证码错误");
				}
				if($_POST["remember"]==1){
					cookie("username",$_POST["username"]);
					cookie("userpassword",$_POST["userpassword"]);

				}else{
					cookie("username",null);
					cookie("userpassword",null);
				}
				$loginname = D("user")->where("phone='%s' or mail='%s'",$_POST["username"],$_POST["username"])->getField("name");
				session("loginname",$loginname);
				$this->success("登录成功",U('Home/Index/index'));
				exit();
			}else{
				$this->error("密码错误");
			}
		}
		$this->assign("username",cookie("username"));
		$this->assign("userpassword",cookie("userpassword"));
		$this->display(":login");
	}
	public function verify_c(){
		$Verify = new \Think\Verify();
		$Verify->fontSize = 18;
		$Verify->length   = 4;
		$Verify->useNoise = false;
		$Verify->codeSet = '0123456789';
		$Verify->imageW = 130;
		$Verify->imageH = 50;
		//$Verify->expire = 600;
		$Verify->entry();
	}
	public function register(){
		$do = $_GET["do"];
		if($do=="add"){
			if($_POST['confirmpassword']&&$_POST['accountpassword']&&$_POST['username']&&$_POST['phonenum']){
				
			}else{
				$this->error("输入项不许为空");
			}
			if(!preg_match("/^1[34578]\d{9}$/", $_POST['phonenum'])){
				$this->error("手机号码格式错误");
			}
			if(D('user')->where("name='%s'",$_POST['username'])->getField('serialnumber')){
				$this->error("用户名已存在");
			}
			if(D('user')->where("phone='%s'",$_POST['phonenum'])->getField('serialnumber')){
				$this->error("手机号已存在");
			}
			$verify = I('param.verify','');
			if(!check_verify($verify)){
				$this->error("验证码错误");
			}
			if($_POST['confirmpassword']==$_POST['accountpassword']){
				$data['name'] = $_POST['username'];
				$data['phone'] = $_POST['phonenum'];
				$data['password'] = $_POST['accountpassword'];
				$data['serialnumber'] = Serialnumber();
				$data['logintime'] = time();
				$data['usertype'] = 1;
				if(D("user")->data($data)->add()){
					$loginname = D("user")->where("phone='%s'",$_POST['phonenum'])->getField("name");
					session("loginname",$loginname);
					$this->success("插入成功",U("Home/Index/index"));
					exit();
				}
			}else{
				$this->error("确认密码和设置密码不符，请检查输入");
			}		}
		$this->display(":register");	
	}
	public function forgotpas(){
		$this->display(":forgot_pas");
	}
	public function myfigure(){
		$serialnumber = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('serialnumber');
		$memberimgurl = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('memberimgurl');
		$noticelist = D("notice")->where("serialnumber='%s'",$serialnumber)->select();

	
		$typeid = $_GET[typeid];
		$this->assign("typeid",$typeid);
		if($typeid){
			$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s' and albumtypeid='%d'",$serialnumber,$typeid)->select();
			$albumimglist = D('album')->join('LEFT JOIN __IMG__ ON __ALBUM__.id=__IMG__.albumid')->where("serialnumber='%s' and albumtypeid='%d'",$serialnumber,$typeid)->select();
		}else{
			$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s'",$serialnumber)->select();
			$albumimglist = D('album')->join('LEFT JOIN __IMG__ ON __ALBUM__.id=__IMG__.albumid')->where("serialnumber='%s'",$serialnumber)->select();
			// 					echo "<pre>";
			// 					print_r($albumimglist);exit();
			// 					echo "</pre>";
		}
		$this->assign('typelist',D("albumtype")->where("serialnumber='%s'",$serialnumber)->order('ordernum asc')->select());
		$this->assign("memberimgurl",$memberimgurl);
		$this->assign("noticelist",$noticelist);
		$this->assign("albumlist",$albumlist);
		$this->assign("loginornot",$_SESSION['loginname']);
		$this->display(":myFigure");
	}
	public function home(){
		$types=$_GET['types'];
		$do = $_GET['do'];
		$serialnumber = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('serialnumber');
		
		if(!$types||$types==1||$types==4){
			//用户中心
			$serialnumber = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('serialnumber');
			if($do=='update'){
				if(!empty($_FILES[myfile][name])){
					$upload = new \Think\Upload();
					$upload->maxSize   =     3145728 ;// 设置附件上传大小
					$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
					$upload->rootPath  =     MODULE_PATH.'Uploads/'; // 设置附件上传根目录
					$upload->savePath  =     ''; // 设置附件上传（子）目录
					// 上传文件
					$info   =   $upload->upload();
					if(!$info) {// 上传错误提示错误信息
						$this->error($upload->getError());
					}else{// 上传成功
						foreach($info as $file){
							$memberimgurl=__ROOT__.substr(MODULE_PATH,1).'Uploads/'.$file['savepath'].$file['savename'];
						}
						D("user")->where("serialnumber='%s'",$serialnumber)->setField('memberimgurl',$memberimgurl);
					}
				}
				
				
				
				$data['nickname'] = $_POST['nickname'];
				$data['mainuri'] = $_POST['mainuri'];
				$data['mail'] = $_POST['mail'];
				D("user")->where("name='%s'",$_SESSION['loginname'])->save($data);
				$noticetitle = $_POST['noticetitle'];
				$ordernum = $_POST['ordernum'];
				$noticemessage = $_POST['noticemessage'];
	
					for($i=0;$i<count($noticetitle);$i++){
							if(!$noticetitle[$i]){
								if(!$noticemessage[$i]){
									continue;
								}
							}
							$noticedata[$i] = array('noticetitle'=>$noticetitle[$i],'noticemessage'=>$noticemessage[$i],'serialnumber'=>$serialnumber,'noticeorder'=>$ordernum[$i]);
					}
					D("notice")->where("serialnumber='%s'",$serialnumber)->delete();
					D("notice")->addAll($noticedata);
				$this->success("修改成功");
				exit();
			}
			
			if($do=='resetpassword'){
				$password = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('password');
				if($_POST['confirmpassword']&&$_POST['newpassword']&&$_POST['oldpassword']){
					if($_POST['confirmpassword']!=$_POST['newpassword']){
						$this->error("确认密码和修改密码不一致");
					}
					if($password == $_POST['oldpassword']){
						D("user")->where("name='%s'",$_SESSION['loginname'])->setField('password',$_POST['newpassword']);
						$this->success("密码修改成功，请重新登录",U('Home/Index/index')."&lg=logout");
						exit();
					}else{
						$this->error("原密码输入错误");
					}
				}else{
					$this->error("密码修改三个数据项目不允许留空");
				}
				
			}
			

			if($do=="updatemessage"){

				if(!empty($_FILES[headimgfile][name])){
					$upload = new \Think\Upload();
					$upload->maxSize   =     3145728 ;// 设置附件上传大小
					$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
					$upload->rootPath  =     MODULE_PATH.'Uploads/'; // 设置附件上传根目录
					$upload->savePath  =     ''; // 设置附件上传（子）目录
					// 上传文件
					$info   =   $upload->upload();
					if(!$info) {// 上传错误提示错误信息
						$this->error($upload->getError());
					}else{// 上传成功
						foreach($info as $file){
							$memberimgurl=__ROOT__.substr(MODULE_PATH,1).'Uploads/'.$file['savepath'].$file['savename'];
						}
						D("user")->where("name='%s'",$_SESSION['loginname'])->setField('headimg',$memberimgurl);
					}
				}
				
				$data['nickname'] = $_POST['nickname'];
				$data['phonename'] = $_POST['name'];
				$data['mail'] = $_POST['mail'];
				$data['phone'] = $_POST['phone'];
				$data['borntime'] = $_POST['year1'].'|'.$_POST['month1'];
				$data['bornaddress'] = $_POST['cmbProvince'].'|'.$_POST['cmbCity'].'|'.$_POST['cmbArea'].'|'.$_POST['detailarea'];
				if(D("user")->where("name='%s'",$_SESSION['loginname'])->save($data)){
					$this->success("修改成功");
					exit();
				}
			}
			$noticedata = D("notice")->where("serialnumber='%s'",$serialnumber)->order('noticeorder asc')->select();
			$listdata = D("user")->where("name='%s'",$_SESSION['loginname'])->select();
		
			$maxordernum = D("notice")->where("serialnumber='%s'",$serialnumber)->max('noticeorder');
			if($maxordernum){
				$this->assign("maxordernum",$maxordernum);
			}
			$this->assign("noticedata",$noticedata);
			$this->assign("listdata",$listdata[0]);
			$borntimearray = explode('|',$listdata[0][borntime]);
			$this->assign("year",$borntimearray[0]);
			$this->assign("month",$borntimearray[1]);
			$bornaddressarray = explode('|',$listdata[0][bornaddress]);
			$this->assign("province",$bornaddressarray[0]);
			$this->assign("city",$bornaddressarray[1]);
			$this->assign("district",$bornaddressarray[2]);
			
			}elseif($types==2){
				if($do=="updatealbumorder"){
					$sort = $_POST['sort'];
					D("user")->where("serialnumber='%s'",$serialnumber)->setField("albumordertype",$sort);
					$this->success("相册排序修改成功");exit();
				}
				if($do=="getalbumdata"){
					header('Content-Type: application/json');
					header('Content-Type: text/html;charset=utf-8');
					$id = $_POST[id];
					$albumitemdata = D("album")->where("id=$id")->select();
					$albumitemdata = $albumitemdata[0];
					$albumitemjsondata = json_encode($albumitemdata);
					echo $albumitemjsondata;
					exit();
				}
				if($do=="updatealbumdata"){
					$id = $_POST[id];
					$data[albumname] = $_POST[albumname];
					$data[albummessage] = $_POST[albummessage];
					D("album")->where("id=$id")->data($data)->save();
					echo $data[albumname];
					exit();
				}
				//相册分类
				if($do=="albumtypeorder"){
					$typejson = $_POST['typejson'];
					$typearray = json_decode($typejson,true);
// 					for($i=0;$i<count($typearray[typejson]);$i++){
// 						$dataList[$i] = array('typename'=>$typearray[typejson][$i][typename],'ordernum'=>$typearray[typejson][$i][ordernum],'serialnumber'=>$typearray[typejson][$i][serialnumber]);
// 					}
// echo "<pre>";
// 					print_r($typearray);exit();
					D('albumtype')->where("serialnumber='%s'",$typearray['serialnumber'])->delete();
					D('albumtype')->addAll($typearray[typejson]);
					$this->success("分类编辑成功");exit();
				}
				//相册服务
				if($do=="createalbum"){
					$albumdata[albumtypeid]=$_POST['altype'];
					$albumdata[albumname]=$_POST['alname'];
					$albumdata[albummessage]=$_POST['almessage'];
					$albumdata['borntime']=time();
					$albumdata['themeid']=0;
					$albumdata['serialnumber']=$serialnumber;
					if(!$_POST['alname']){
						echo "相册名不允许为空";exit();
					}
					if(D('album')->where("albumname='%s'",$_POST['alname'])->getField('id')){
						echo "相册名已存在，请重新输入";exit();
					}
					if(D('album')->data($albumdata)->add()){
						echo "添加空相册成功";exit();
					}
				}
				
				if($do=="updatealbum"){
					//修改相册	
					$albumupdatedata[albumname] = $_POST[albumname];
					$albumupdatedata[albummessage] = $_POST[albummessage];
					$albumupdatedata[albumtypeid] = $_POST[albumtypeid];
					if(D("album")->where("id='%d'",$_POST[myalbumid])->data($albumupdatedata)->save()){
						echo "修改成功!";exit();
					}else{
						echo "修改失败!";exit();
					}
				}
				if($do=="updatealbumpassword"){
					//修改相册密码
					$confirmalbumpassword = $_POST['confirmalbumpassword'];
					$albumpassword = $_POST['albumpassword'];
					
					if($confirmalbumpassword!=$albumpassword){
						$this->error("确认密码和原密码输入不符");
					}elseif($confirmalbumpassword==$albumpassword){
						$albumidarray = $_POST['albumid'];
						foreach($albumidarray as $key=>$value){
							D('album')->where("id=$value")->setField("password",$albumpassword);
						}
						$this->success("密码设置成功");
						exit();
					}
				}
				if($do=="deletealbum"){
					$albumid = $_GET['albumid'];
					D("album")->where("id='%d'",$albumid)->delete();
					D("img")->where("albumid='%d'",$albumid)->delete();
					echo "删除成功";
					exit();
				}
				if($do=="uploadimg"){
					$albumid = $_POST['albumid'];
					$thirdparty = D("admin")->select();
					$config = array(
							'maxSize'    =>   5*1024*1024,
							'rootPath'   =>    MODULE_PATH.'Uploads/',
							'savePath'   =>    '',
							'saveName'   =>    array('uniqid',''),
							'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
							'autoSub'    =>    true,
							'subName'    =>    array('date','Ymd'),
					);
					$config_qiniu=array(
							'accessKey' => $thirdparty[0][qiniukey], //这里填七牛AK
							'secretKey' => $thirdparty[0][qiniusecret], //这里填七牛SK
							'domain' => $thirdparty[0][qiniuurl],//这里是查看七牛图片时的图片链接地址的域名
							'bucket' => $thirdparty[0][bucket]//这里是七牛中的“空间”
					);
					
					$Upload = new \Think\Upload($config,'Qiniu',$config_qiniu);
					$resultmsg = $Upload->uploadOne($_FILES['albumfile']);
					if(!$resultmsg){
						echo "未上传图片文件";exit();
					}else{
						foreach($resultmsg as $key=>$value){
							$data[$key] = array('imgurl'=>$value[url],'albumid'=>$albumid);
							
						}
						D("img")->addAll($data);
						//$imgidlist = D("img")->where("albumid=$albumid")->field('id')->select();
						
						//$albumimgidjson = D("album")->where("id=$albumid")->getField("albumimgid");
						//$albumimgarray = json_decode($albumimgidjson,true);
						$firstimgurl = D("img")->where("albumid=$albumid")->limit(1)->select();
						D("album")->where("id=$albumid")->setField("albumimgid",$firstimgurl[0][imgurl]);
						echo "图片上传成功";exit();
					}
				}
				$orderby = D('user')->where("serialnumber='%s'",$serialnumber)->getField('albumordertype');
				if($orderby==1){
					$albumorder = "borntime asc";
				}
				elseif($orderby==2){
					$albumorder = "albumname asc";
				}
				elseif($orderby==3){
					$albumorder = "albumorder asc";
				}
				
				//->order($albumorder)
				$serialnumber = D("user")->where("name='%s'",$_SESSION['loginname'])->getField("serialnumber");
				$typeid = $_GET[typeid];
				$this->assign("typeid",$typeid);
				if($typeid){
					$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s' and albumtypeid='%d'",$serialnumber,$typeid)->order($albumorder)->select();
					$albumimglist = D('album')->join('LEFT JOIN __IMG__ ON __ALBUM__.id=__IMG__.albumid')->where("serialnumber='%s' and albumtypeid='%d'",$serialnumber,$typeid)->select();
				}else{
					$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s'",$serialnumber)->order($albumorder)->select();
					$albumimglist = D('album')->join('LEFT JOIN __IMG__ ON __ALBUM__.id=__IMG__.albumid')->where("serialnumber='%s'",$serialnumber)->select();
// 					echo "<pre>";
// 					print_r($albumimglist);exit();
// 					echo "</pre>";
				}
				if($do=="updateface"){
					$id = $_GET[albumid];
					$faceimgsrc = $_POST['faceimgsrc'];
					D("album")->where("id=$id")->setField("albumimgid",$faceimgsrc);
					echo $faceimgsrc;exit();
					
				}
				if($do=="getalbumdetail"){
					$id = $_POST['id'];
					foreach($albumimglist as $key=>$value){
						if($value[albumid]==$id){
							/* array_splice($albumimglist, $key, 1); */
							$lunbodata[] = $value;
						}
					}
					echo json_encode($lunbodata);exit();
				}
				$albumordertype = D("user")->where("serialnumber='%s'",$serialnumber)->getField('albumordertype');
				//$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s'",$serialnumber)->select();
				$this->assign('typelist',D("albumtype")->where("serialnumber='%s'",$serialnumber)->order('ordernum asc')->select());
				$this->assign('host',D("user")->where("name='%s'",$_SESSION['loginname'])->getField("serialnumber"));
				$this->assign('albumordertype',$albumordertype);
				$this->assign('albumlist',$albumlist);
				$this->assign('albumimglist',$albumimglist);
			}elseif($types==3){
				//装修相册
				if($do=="updatetheme"){
					$id = $_POST[id];
					$themeid = $_POST[themeid];
					D('album')->where("id=$id")->setField("themeid",$themeid);
					$photoframeimgurl = D('theme')->where("tmid=$themeid")->getField("photoframeimgurl");
					echo $photoframeimgurl;
					exit();
				}
				$albumlist = D('album')->where("serialnumber='%s'",$serialnumber)->select();
				$albumlist = D('album')->join('LEFT JOIN __THEME__ ON __ALBUM__.themeid=__THEME__.tmid')->where("serialnumber='%s'",$serialnumber)->select();
				$themedatalist = D('theme')->select();
				$this->assign("albumlist",$albumlist);
				$this->assign("themedatalist",$themedatalist);
				$this->display(":home");
				exit();
				
			}elseif($types==5){
				//vip服务
				if($do=="getvip"){
// 					$c = new AopClient;
// 					$c->gatewayUrl = "https://openapi.alipay.com/gateway.do";
// 					$c->appId = "2017060707438002";
// 					$c->rsaPrivateKey = 'MIIEpgIBAAKCAQEAt0VVc3wpVsBZpbjinPKua8etPL7LOIZ5t1JBK+Akrc8/kcuKEwTf5NemvJ/nHoOJu2Y4M7TL6b2ePulXPGMsr6igAEOZCJlouA61am0o0mQofwY/IG3uJQRZP5vZh3XB9Ab4yu3uori8nAbo00E5M5FKheyR9C63PEu04mxKZlPL/1nOov2wCkdNbMdbWsdbVnER0ADgRaS8Y1LmgkfYLJTFQpOxPtlgZEwKzTLmp9EvMQ3HC/r8xyEjmGUwcm0IrmHEqRc9I5mDLE/SMpgvzOJTrKXSDX6AcrEU3Nbgeki0RZYzZ0cddi3K/GH4MFIjbOF8qUDUqPyT01cxddz19QIDAQABAoIBAQCmn6LRHFF5Tegzg6SEjR+HXkNitxSMj7aZtW8LNP4kCAkDxMoEAKqOpIIzfC3k0DKo7oaqe/XozTzSddOaU5CNJAJUOyEncFKFBNprqFM09VrcIhHCqi+Z+BosesWLIsTz2GLaHPiZeNwB/0Yuy132RGI84JjSKKbvauVJ9qqt3HeHNITedNPGG037AXl9ce/r8ij0AzMLUq3mE8t216tNfC4wfK+PysfHZXKkn1wZbuk5T+Gnnfoi5zrh4nTzUhutwEdv0cvuX3aqwbw2mmkhGsIqxv6xk4K0asu4cYqvBPRrN39AZkFILdvOlfEZ2LTUvFF449rWeqJN5KHvO3gBAoGBAONpOQtnWgB4qvU1MYkPzZS+1tawbJPiXdeJuJ21lm4HcLbAXLKcGvUfa+X9A1vaeQ1pbRESwp2BzmGQ2ujLhWEp9nWLOuwhhRZzbn40gY2fW2MS2oNDXlsQGwYOTeHOk8O92LylyHBh6Z+l54s8rddRQ1kF9mDwlyklzt/y08fZAoGBAM5Pi6zg7ONJFyvZwMRGHVPMzQLdZWKZJaa8uSS7fmXcYNglo78QNRsse83g4bjA7FTAghKtDeGaslITg061LFVNB4pN31wBnk1U0pZLQjfIUf5TXJcjsEhFyyCHVC/AQzkw71OYFnQ8NbdQfXOe6G11mQaJfTzAAM67QFhNA8l9AoGBAMVhyAx42Sp9kc0hLWyMleBcP/a5zJQTL2Zr+BySxw2bUZ6dmhfA3LkTW8CUebzZBKa6cdsW0GqLh0kxxH+4Xn12QZ/GiA76DRzudeH+ys/UmCqG67hw2c3qTbpU4g5zEdgcyKj8r9uzcGaMRkuZED5KH01+mlmLmXgyg7vndSAJAoGBAL8G9GOMmIsTADuAEncqHLmdJi6C5P9Yon4yvJOAb9bNKXa501Z0IVgZ5kCI+zfgmnMXFNlKF1JPtNE+dBSKuJP7EQJEfI5qiTM9WQgEgzm3aAQ/F7pyNyWUSjLCW3cjZJst7kvOxOu3XF1yT9agysGfY6Oj5qw7dAP3aerY1KrZAoGBAKGlx7POZToWiM+RGI6UuxrW4gMgsCAHj57ok+IiJbTftCsO0KjpEddcxK07SFxCrrkhX6sVfcovsEmBwoqCla6BEwJYsuNM52y3S9bp4+bkVwy3BB49ui6aal2zLVEp9//GgG6WdbgzsYI2wXWlbEgW8TgSxtn+e2eSsJuJLXz7' ;
// 					$c->format = "json";
// 					$c->charset= "GBK";
// 					$c->signType= "RSA2";
// 					$c->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt0VVc3wpVsBZpbjinPKua8etPL7LOIZ5t1JBK+Akrc8/kcuKEwTf5NemvJ/nHoOJu2Y4M7TL6b2ePulXPGMsr6igAEOZCJlouA61am0o0mQofwY/IG3uJQRZP5vZh3XB9Ab4yu3uori8nAbo00E5M5FKheyR9C63PEu04mxKZlPL/1nOov2wCkdNbMdbWsdbVnER0ADgRaS8Y1LmgkfYLJTFQpOxPtlgZEwKzTLmp9EvMQ3HC/r8xyEjmGUwcm0IrmHEqRc9I5mDLE/SMpgvzOJTrKXSDX6AcrEU3Nbgeki0RZYzZ0cddi3K/GH4MFIjbOF8qUDUqPyT01cxddz19QIDAQAB';
// 					//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.open.public.template.message.industry.modify
// 					$request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
// 					//SDK已经封装掉了公共参数，这里只需要传入业务参数
// 					//此次只是参数展示，未进行字符串转义，实际情况下请转义
// 					$bizContent = "{" +
// 					"    \"primary_industry_name\":\"IT科技/IT软件与服务\"," +
// 					"    \"primary_industry_code\":\"10001/20102\"," +
// 					"    \"secondary_industry_code\":\"10001/20102\"," +
// 					"    \"secondary_industry_name\":\"IT科技/IT软件与服务\"" +
// 					" }";
// 					$request->setBizContent($bizContent);

// 					$response= $c->execute($request);
// 					//if(response.isSuccess()){
// 						print_r("nihao");
// 					//}

					$vipborntime = D("user")->where("name='%s'",$_SESSION['loginname'])->setField('vipborntime',time());
					if(D("user")->where("name='%s'",$_SESSION['loginname'])->setField('vipyear',$_POST['vipyeartime'])){
						$this->success("购买成功，当天生效");
						exit();
					}else{
						$this->error("请输入购买年数");
					}
				}
				$vipyear = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('vipyear');
				
				$vipborntime = D("user")->where("name='%s'",$_SESSION['loginname'])->getField('vipborntime');
				$releasetime = ceil((strtotime(date("Y-m-d",$vipborntime)." +".$vipyear." year")-time())/86400);
				
				$this->assign("releasetime",$releasetime);
			}
			$this->display(":home");
	}
}